package distribution

import (
	"activity_srv/activityclient"
	"api/internal/respons"
	"api/internal/svc"
	"api/internal/types"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetDistributionLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetDistributionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDistributionLogic {
	return &GetDistributionLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// GetDistribution 获取分销信息
func (l *GetDistributionLogic) GetDistribution(req *types.GetDistributionRequest) (resp *types.Response, err error) {
	distribution, err := l.svcCtx.ActivityRpc.GetDistribution(l.ctx, &activityclient.GetDistributionRequest{
		Distribution: req.Distribution,
	})
	if err != nil {
		return respons.Error(400, "服务端错误", err.Error()), err
	}

	return respons.Success(distribution), nil
}
